Page({
  setInter: '',
  setInter2: '',
  data: {
    num: 0, //起始值
    num_fix: '00'
  },
  onShow() {
    this.setInter2 = setInterval(() => {
      this.time();
    }, 50);
  },
  time() {
    this.setInter = setInterval(() => {
      clearInterval(this.setInter);
      wx.getBatteryInfo({
        success: res => {
          if (res.isCharging == true) {
            var num = this.data.num + Math.floor(Math.random() * 10);
            var num_fix = Math.floor((Math.random() + 1) * 50)
            this.setData({
              num,
              num_fix
            });
          } else {
            clearInterval(this.setInter);
          }
        }
      })
    }, 1);
  },
  endSetInter() {
    clearInterval(this.setInter);
    clearInterval(this.setInter2);
  },
  onUnload() {
    this.endSetInter()
  },
  // 充值
  chongzhi() {
    wx.getBatteryInfo({
      success: res => {
        if (res.isCharging == false) {
          wx.showToast({
            title: '插上充电器自动充值！',
            icon: 'error'
          })
        } else {
          wx.showToast({
            title: '暴富中...',
            icon: "none"
          })
        }
      }
    })
  },
  // 提现
  tixian() {
    wx.showToast({
      title: '年年有余',
      icon: 'none'
    })
  },
  onShareAppMessage() {
    return {
      title: "手机插上充电就能充钱？",
      path: "/pages/happyTools/pages/wechatMoney/index",
      imageUrl: '/images/function_icon/wechatMoney.png',
    }
  },
  onShareTimeline() {
    return {
      title: '手机插上充电就能充钱？',
      imageUrl: '/images/function_icon/wechatMoney.png',
    }
  },
});